package com.yvon.maple.service.base.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author : Yvon
 * @since : 2021-12-04
 */
public class Base64FileUtil {

    public static MultipartFile base64ToMultipart(String base64) {
        String[] baseStrs = base64.split(StrUtil.COMMA);
        byte[] b;
        b = Base64.decode(baseStrs[1]);
        for(int i = 0; i < b.length; ++i) {
            if (b[i] < 0) {
                b[i] += 256;
            }
        }
        return new Base64DecodedMultipartFile(b, baseStrs[0]);
    }
}
